import list from "./page.json"
import type {MockMethod} from "vite-plugin-mock";
import success from "../success.json"
import {findItemById} from "../utils";

export default [
    {
        url: "/notice/list",
        method: "post",
        response: ({body, query}: any) => {
            console.log('body>>>>>>>>', body)
            console.log('query>>>>>>>>', query)
            let find = JSON.parse(JSON.stringify(list));
            if (body.data.title != "") {
                find = list.data.list.filter((item) => {
                    return item.title.indexOf(body.data.title) != -1;
                })
                let result = JSON.parse(JSON.stringify(success));
                result.data.total = find.length;
                result.data.list = find;
                return result;
            } else {
                return list;
            }

        }
    },
    {
        url: "/notice/detail",
        method: "get",
        response: ({query}: any) => {
            //console.log(query);
            let info = findItemById(list.data.list, query.id, "noticeId");
            let infoResult = null;
            if (info) {
                infoResult = JSON.parse(JSON.stringify(info));
            }
            if (info && info.children) {
                infoResult.children = null;
            }

            let result = JSON.parse(JSON.stringify(success));
            // @ts-ignore
            result.data = infoResult;
            return result;
        }
    },
    {
        url: "/notice/save",
        method: "post",
        response: () => {
            return success;
        }
    }
] as MockMethod[];
